package com.itheima.Jiuye14;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

//第一题：分析以下需求，并用代码实现
//        一共有100水杯,请通过实体店和官网来进行销售
//        最后统计实体店和官网分别出售的数量
public class Zuoye1 implements Runnable{
   // Thread thread = new Thread();
    private Lock lock = new ReentrantLock();
    private int conut =0;
    private int b = 0;
    private int a = 100;

    @Override
    public void run() {
          while (true){
              try {
                  lock.lock();
                  if (a <= 0){
                      break;
                  }else {
                      a--;
                      System.out.println(Thread.currentThread().getName()+"在卖水杯，还剩"+a+"个水杯");
                      if (Thread.currentThread().getName().equals("线上店")){
                      conut++;
                      }else {
                          b++;
                      }
                  }
              } finally {
               lock.unlock();
              }
          }
                      System.out.println("线上卖了"+conut+"杯水");
                      System.out.println("实体店卖了"+b+"杯水");
    }
}
